package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.OlivePlantArea;
import com.ruoyi.system.mapper.OlivePlantAreaMapper;
import com.ruoyi.system.service.IOlivePlantAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 种植区信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-10-30
 */
@Service
public class OlivePlantAreaServiceImpl implements IOlivePlantAreaService
{
    @Autowired
    private OlivePlantAreaMapper olivePlantAreaMapper;

    /**
     * 查询种植区信息
     * 
     * @param plantAreaId 种植区信息主键
     * @return 种植区信息
     */
    @Override
    public OlivePlantArea selectOlivePlantAreaByPlantAreaId(Long plantAreaId)
    {
        return olivePlantAreaMapper.selectOlivePlantAreaByPlantAreaId(plantAreaId);
    }

    /**
     * 查询种植区信息列表
     * 
     * @param olivePlantArea 种植区信息
     * @return 种植区信息
     */
    @Override
    public List<OlivePlantArea> selectOlivePlantAreaList(OlivePlantArea olivePlantArea)
    {
        return olivePlantAreaMapper.selectOlivePlantAreaList(olivePlantArea);
    }

    /**
     * 新增种植区信息
     * 
     * @param olivePlantArea 种植区信息
     * @return 结果
     */
    @Override
    public int insertOlivePlantArea(OlivePlantArea olivePlantArea)
    {
        return olivePlantAreaMapper.insertOlivePlantArea(olivePlantArea);
    }

    /**
     * 修改种植区信息
     * 
     * @param olivePlantArea 种植区信息
     * @return 结果
     */
    @Override
    public int updateOlivePlantArea(OlivePlantArea olivePlantArea)
    {
        olivePlantArea.setUpdateTime(DateUtils.getNowDate());
        return olivePlantAreaMapper.updateOlivePlantArea(olivePlantArea);
    }

    /**
     * 批量删除种植区信息
     * 
     * @param plantAreaIds 需要删除的种植区信息主键
     * @return 结果
     */
    @Override
    public int deleteOlivePlantAreaByPlantAreaIds(Long[] plantAreaIds)
    {
        return olivePlantAreaMapper.deleteOlivePlantAreaByPlantAreaIds(plantAreaIds);
    }

    /**
     * 删除种植区信息信息
     * 
     * @param plantAreaId 种植区信息主键
     * @return 结果
     */
    @Override
    public int deleteOlivePlantAreaByPlantAreaId(Long plantAreaId)
    {
        return olivePlantAreaMapper.deleteOlivePlantAreaByPlantAreaId(plantAreaId);
    }



    /**
     * 校验种植区编码是否唯一
     */
    public boolean checkOlivePlantAreaIdUnique(OlivePlantArea olivePlantArea){
        Long plant_area_id = StringUtils.isNull(olivePlantArea.getPlantAreaId())?-1:olivePlantArea.getPlantAreaId();
        OlivePlantArea info = olivePlantAreaMapper.checkOlivePlantAreaPlantareaidUnique(plant_area_id);
        if(StringUtils.isNotNull(info) && info.getPlantAreaId().equals(plant_area_id)){
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;

    }
}
